package com.mansoor.app.islamicnames.Predicates;

import com.mansoor.app.islamicnames.beans.Name;
import com.mansoor.app.islamicnames.util.AppConstants;
import org.apache.commons.collections.Predicate;


/**
 * Created by IntelliJ IDEA.
 * User: TKMAQ61
 * Date: Oct 15, 2009
 * Time: 11:04:54 AM
 */
public class SearchNameList implements Predicate
{
    private final String alphabet;
    private final String gender;
    private final Integer page;
    public SearchNameList(String alphabet, String gender, Integer page)
    {
        this.alphabet = alphabet;
        this.gender = gender;
        this.page = page;
    }


    public boolean evaluate(Object o)
    {
        boolean result = false;
        Name name= (Name) o;

        if (gender == null)
        {
            if (name.getName().startsWith(alphabet) && name.getId()<=(page* AppConstants.RECORD_PER_PAGE)  && name.getId()>((page-1)* AppConstants.RECORD_PER_PAGE))
            {
                result = true;
            }
        }
        else
        {
            if (name.getName().startsWith(alphabet) && name.getGender().equalsIgnoreCase(gender) && name.getId()<=(page* AppConstants.RECORD_PER_PAGE) && name.getId()>((page-1)* AppConstants.RECORD_PER_PAGE))
            {
                result = true;
            }
        }

        return result;  //To change body of implemented methods use File | Settings | File Templates.
    }
}
